package app.fitness.fragment;

import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

import com.razerzone.android.fitness.R;

import define.Constants;

public class DownloadNabuUtilityFragment extends Fragment implements
		OnClickListener {

	/**
	 * String section
	 */
	
	/**
	 * Data section
	 */

	/**
	 * View section
	 */
	private Button mBtnDownloadNabuUtility;

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_download_utility_app:
			/**
			 * Transfer to Play Store to download the Nabu Utility App Show
			 * message to notify the user should do it
			 */
			Toast.makeText(getActivity(),
					getString(R.string.go_to_play_store_download_utility_app),
					Toast.LENGTH_SHORT).show();

			String appPackageName = Constants.PACKAGE_NAME;
			Intent marketIntent = new Intent(Intent.ACTION_VIEW,
					Uri.parse("market://details?id=" + appPackageName));
			marketIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY
					| Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
					| Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
			startActivity(marketIntent);
			break;
		default:
			break;
		}
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		/**
		 * Set Orientation for page
		 */
		getActivity().setRequestedOrientation(
				ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

		View v = inflater.inflate(R.layout.fragment_download_utility_app,
				container, false);

		// Initial variables
		initialVariables(v);
		initialData();

		return v;
	}

	@Override
	public void onDestroyView() {
		super.onDestroyView();
		
		getActivity().finish();
	}
	
	/**
	 * Initial methods
	 */

	private void initialData() {
		mBtnDownloadNabuUtility.setOnClickListener(this);
	}

	private void initialVariables(View v) {
		mBtnDownloadNabuUtility = (Button) v
				.findViewById(R.id.btn_download_utility_app);
	}

	/**
	 * Basic methods
	 */
}
